/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Attendance;

import Admission.AdmissionBean;
import Student.StudentBean;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

/**
 *
 * @author Mukesh
 */
public class Query {
   static Connection con=null;
public static Vector getStudents(int courseid, int sem) throws SQLException
{
    Vector<Object> list=new Vector<Object>();
    try{
        con=DBConnection.Connection.getConnection();
        PreparedStatement pre=con.prepareStatement("select * from admission a left join (select admission_id,student_name from student) s on a.admission_id=s.admission_id where a.course_id=? and a.semester=?");
        pre.setInt(1, courseid);
        pre.setInt(2, sem);
        ResultSet rs=pre.executeQuery();
        while(rs.next())
        {
            AdmissionBean ab=new AdmissionBean();
            StudentBean sb=new StudentBean();
            
            ab.setAddmissionId(rs.getInt("ADMISSION_ID"));
            ab.setRollNumber(rs.getString("ROLL_NUMBER"));
            ab.setCourseId(rs.getInt("COURSE_ID"));
            ab.setSemester(rs.getInt("SEMESTER"));
            sb.setStudentName(rs.getString("STUDENT_NAME"));
            
            ab.setStudentBean(sb);
            list.add(ab);
        }
    }catch(Exception e){
        System.out.println(e);
    }finally{con.close();}
    return list;
    }
}
